package com.raymond.controller;

import com.alibaba.fastjson.JSONObject;
import com.raymond.entity.commons.DtoResult;
import com.raymond.entity.commons.PageResponse;
import com.raymond.entity.commons.SummaryResponse;
import com.raymond.entity.settlement.OrderSettlementDetailEntity;
import com.raymond.entity.settlement.OrderSettlementDetailPageQueryReqVo;
import com.raymond.entity.settlement.OrderSettlementEntity;
import com.raymond.entity.settlement.OrderSettlementPageQueryReqVo;
import com.raymond.service.OrderSettlementService;
import com.raymond.util.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * desc-结算单控制器
 *
 * @author houmenghe
 * @date 2025/04/21 17:32
 **/
@Slf4j
@Api(tags = "结算单控制器:OrderSettlementController")
@RestController
@RequestMapping("/v1/orderSettlement")
public class OrderSettlementController {

    @Autowired
    private OrderSettlementService orderSettlementService;

    @PostMapping("/searchList")
    @ApiOperation(value = "查询结算列表", notes = "查询结算列表")
    public DtoResult<SummaryResponse<OrderSettlementEntity>> searchList(@RequestBody OrderSettlementPageQueryReqVo query) {
        log.info("查询结算列表：请求参数：{}", JSONObject.toJSONString(query));
        return DtoResult.ok(PageUtil.process(query,
                () -> orderSettlementService.searchSettlementList(query),
                () -> orderSettlementService.searchSettlementListCount(query),
                () -> orderSettlementService.searchSettlementListSummaryCount(query)));
    }

    @GetMapping("/get/{sysNo}")
    @ApiOperation(value = "查询结算单详情", notes = "查询结算单详情")
    public DtoResult<OrderSettlementEntity> searchList(@PathVariable("sysNo") Long sysNo) {
        log.info("查询结算列表：请求参数：{}", JSONObject.toJSONString(sysNo));
        return DtoResult.ok(orderSettlementService.getOrderSettlement(sysNo));
    }

    @PostMapping("/queryDetailListBySettlementSysNo")
    @ApiOperation(value = "根据结算单编号查询结算明细分页列表", notes = "根据结算单编号查询结算明细分页列表")
    public DtoResult<PageResponse<OrderSettlementDetailEntity>> queryDetailListBySettlementSysNo(@RequestBody OrderSettlementDetailPageQueryReqVo query) {
        log.info("查询结算列表：请求参数：{}", JSONObject.toJSONString(query));
        return DtoResult.ok(orderSettlementService.queryDetailListBySettlementSysNo(query));
    }

    @GetMapping("/batchInsertMockData/{count}")
    @ApiOperation(value = "mock接口：批量插入结算数据", notes = "mock接口：批量插入结算数据")
    public DtoResult<Void> batchInsertMockData(@PathVariable("count") Integer count) {
        orderSettlementService.batchInsertMockData(count);
        return DtoResult.ok(null);
    }
}
